package src.Base;

import java.util.ArrayList;

public class SyntaxWord {
    boolean isLoop;
    Word token;
    String type;
    Symbol2 symbol = null;
    ArrayList<SyntaxWord> children;
    String returnType = "";
    String regId = "";
    String value = "";
    String stmtType = "";
    int TrueId;
    int FalseId;
    int StmtId = -1;
    int ContinueId = -1;

    int BreakId = -1;

    int forElements[] = null;
    public SyntaxWord(String type, Word token){
        this.token = token;
        this.type = type;
        children = new ArrayList<>();
    }
    public void addChild(SyntaxWord child){
        children.add(child);
    }
    public String getType(){return type;}
    public ArrayList<SyntaxWord> getChildren(){return children;}
    public boolean isEnd(){
        return type==null;
    }
    public Word getToken(){
        return token;
    }

    public void setLoop(boolean loop) {
        isLoop = loop;
    }
    public boolean getIsLoop(){
        return isLoop;
    }
    public String getChild0Content(){
        return this.children.get(0).getToken().getContent();
    }
    public int getLine(){
        return this.children.get(0).getToken().getLine();
    }
    public boolean typeCheck(String type){
        if(this.type == null){
            return false;
        }else {
            return this.type.equals(type);
        }
    }

    public void setSymbol(Symbol2 tmp){
        this.symbol = tmp;
    }

    public Symbol2 getSymbol(){
        if(symbol == null){
            return new Symbol2(0);
        }
        return symbol;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getRegId() {
        return regId;
    }

    public void setRegId(String regId) {
        this.regId = regId;
    }

    public String getValue() {
        return value;
    }

    public void setVoid(){
        this.returnType = "void";
    }
    public void setInt(){
        this.returnType = "i32";
    }
    public String getReturnType(){
        if (returnType.length() == 0){
            throw new RuntimeException();
        }
        return returnType;
    }

    public void setStmtType(String stmtType){
        this.stmtType = stmtType;
    }
    public String getStmtType(){return stmtType;};

    public void setStmtId(int stmtId) {
        StmtId = stmtId;
    }

    public void setTrueId(int trueId) {
        TrueId = trueId;
    }

    public void setFalseId(int falseId) {
        FalseId = falseId;
    }

    public int getFalseId() {
        return FalseId;
    }

    public int getTrueId() {
        return TrueId;
    }

    public int getStmtId() {
        return StmtId;
    }

    public void setContinueId(int continueId) {
        ContinueId = continueId;
    }

    public int getContinueId() {
        return ContinueId;
    }

    public void setBreakId(int id) {
        BreakId = id;
    }
    public int getBreakId(){
        return BreakId;
    }

    public void setForElements(int[] forElements) {
        this.forElements = forElements;
    }

    public int[] getForElements() {
        return forElements;
    }
}
